{% extends "PlatBundle::layout.html.twig" %}

{% block title %}勋章管理{% endblock %}

{% block css %}
    <link href="{{ asset('assets/css/combo.select.css') }}" rel="stylesheet">
    <style>
        .combo-select{
            margin-bottom: 0;
        }
    </style>
{% endblock %}


{% block top %}
    {#{{ dump() }}#}
    {{ parent() }}
{% endblock %}


{% block left_body_top %}
    {{ parent() }}
{% endblock %}


{% block left_body %}
    {{ parent() }}
{% endblock %}


    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">勋章管理</span>
            </div>
        </div>
        <div class="main-content">
            <div class="mes-content">
                <div class="main-mes-top">
                    <div class="fl">
                        <a class="release-btn fl" href="{{ path('plat_edit_medal',{id:'0'}) }}" style="width:140px;">
                            <div class="train-width" style="width: 96px;">
                                <span class="me-icon fl"></span>
                                <span class="re-text fl">添加新勋章</span>
                            </div>
                        </a>
                    </div>

                    <div class="fr">

                        <div class="mes-input fl">
                            <select name="company">
                                <option value="">请输入或选择勋章名称</option>
                                {% for item in data %}
                                <option value="{{ item.medal_name }}">{{ item.medal_name }}</option>
                                {% endfor %}
                            </select>
                        </div>

                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released fl">勋章列表</div>

                    <table class="table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th class="center-th">序号</th>
                            <th class="center-th">勋章图片</th>
                            <th class="center-th">勋章名称</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>



                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">


                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>

    {#<div class="pop-status opacity"></div>#}
{% endblock %}


{% block body %}{% endblock %}


{% block box %}

{% endblock %}

{% block javascript %}
<script src="{{ asset('assets/js/jquery.combo.select.js') }}"></script>
    {{ parent() }}
<script type="text/javascript">

        SidebarHighlighting(3);

        // 查询条件
        var medal_name = "";

        $('select').comboSelect();

        $('body').on('click','.tab-disable', function() {
            var id = $(this).data("id");

            if (confirm('您确定要删除吗？')) {
                $.post("{{ path('api_platform_delete_medal') }}",{id:id},function(data){
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, data.message, 1, '', true);
                        location.reload();
//                        $("table tbody").empty();
//                        page_times = 0;
//                        getList(1);

                    } else {
                        popStatus(2, data.message, 1, '', true);

                    }


                })

            }
        });


        //点击取消
        $('.mem-cancel, .close-icon').on('click', function() {
            ComMesClose();
        });

        // 弹框显示函数
        function ComMesClose() {
            $('.pop-status').hide();
            $('.pop-first').hide();
        }

        function ComMesOpen() {
            $('.pop-status').show();
            $('.pop-first').show();
        }

        //勋章列表
        var page_times = 0;
        function getList(page,medal_name){
            page_times++;
            var param = {page:page};

            if($.trim(medal_name) != ""){
                param.medal_name = medal_name;
            }

            $.getJSON("{{ path('api_platform_medal_list') }}",param,function(data){
                $("table tbody").empty();
                console.log(data);
                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                if(allpage == 0){
                    $(".pagination").empty();
                }

                var item = data.data.info;

                for(var i in item){
                    var key = parseInt(i)+1;

                    var list_order_num = parseInt((parseInt(page)-1)*10+key);

                    var html = '';

                    var img_src = "{{ asset('') }}"+item[i].thumb;

                    var info = "{{ path('plat_edit_medal',{id:'457839238652'}) }}".replace("457839238652",item[i].id);
                    html += '<tr>';
                    html += '<td class="a-line center-th">'+ list_order_num +'</td>';
                    html += '<td class="a-line center-th">';
                    html += '<img src="'+ img_src +'" class="modal-img" >';
                    html += '</td>';
                    html += '<td class="center-th">'+ item[i].medal_name +'</td>';
                    html += '<td class="center-th">';
                    html += '<a href="'+ info +'" class="table-opera tab-edit" data-id="'+ item[i].id +'">编辑 |</a>';
                    html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'">删除</span>';
                    html += '</td>';
                    html += '</tr>';

                    $("table tbody").append(html);

                }

            })

        }

        addSearchAction(1);  //4

        //5
        function addSearchAction(page){

            getList(page,medal_name);
        }

        //查询
        $(".mes-query-btn").click(function(){

            medal_name = $("select[name='company']").val();

            var input_medal = $(".combo-input.text-input").val();



            if($.trim(medal_name) == "" && $.trim(input_medal) != ""){
                medal_name = input_medal;
            }


            page_times = 0;
            addSearchAction(1);

        })

</script>

{% endblock %}
